package com.pagepub.core.tag.validator;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class ValidatePassword extends FormValidateBasic {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7558673745605902288L;

	private String submitvalidate;
    private String rightimage;
    private String rightwordcolor; 
	public String getRightimage() {
		return rightimage;
	}

	public void setRightimage(String rightimage) {
		this.rightimage = rightimage;
	}

	public String getRightwordcolor() {
		return rightwordcolor;
	}

	public void setRightwordcolor(String rightwordcolor) {
		this.rightwordcolor = rightwordcolor;
	}

	public String getSubmitvalidate() {
		return submitvalidate;
	}

	public void setSubmitvalidate(String submitvalidate) {
		this.submitvalidate = submitvalidate;
	}

	public int doStartTag() throws JspException {
JspWriter out=this.pageContext.getOut();		
		
		try {
			out.print(validatepassword());
		} catch (IOException e) {
			// TODO 自动生成 catch 块


			e.printStackTrace();
		}
		return super.doStartTag();
	}

	
  public StringBuffer validatepassword(){
	  ValidateEmptyLenDisplay validate=new ValidateEmptyLenDisplay();
	  validate.setRightimage(rightimage);
	  validate.setRightwordcolor(rightwordcolor);
	  validate.setSubmitvalidate(submitvalidate);
	  validate.setWordcolor(wordcolor);
	  validate.setWrongimage(wrongimage);
	  StringBuffer string=new StringBuffer();
	  String emptyelement="";
	    String pluselement="";
	     if(this.submitvalidate.equalsIgnoreCase("true")){
			emptyelement="emptyelement(realname);";
			pluselement=" pluselement(realname);";
			}
	   string.append("<script language=\"javascript\">");
	   string.append("var passwordvalue=\"\";");
	   string.append("function validatepassword(realvalue,min,max,spanname,realname){");
	   string.append("passwordvalue=realvalue; validateemptylendisplay(realvalue,min,max,spanname,realname);");
	   string.append("}");
	   string.append("function validatemakesurepassword(realvalue,spanname,realname){");
	   string.append("  if(passwordvalue!=\"\"){");
	   string.append("if(realvalue==passwordvalue) { ");	    
	   string.append("	message=\"恭喜!\"+realname+\"填写正确！\";");
	   string.append("	imgurl=\"<img src=\\\""+this.rightimage+"\\\"/>\";	");
	   string.append(emptyelement);
	   string.append("document.getElementById(spanname).innerHTML=imgurl+\"<font color=\\\"" + this.rightwordcolor
				+ "\\\">\"+message+\"</font>\";");	
	   string.append("}");
	   
	   string.append("else { ");
	   string.append("	message=\"确认密码填写有误！\";");
	   string.append("	imgurl=\"<img src=\\\""+this.wrongimage+"\\\"/>\";	");
	   string.append(pluselement);
	   string.append(this.display());
	   string.append("}");
	   
	   string.append(" }");
	  
	   string.append("}");
	  
	   string.append("</script>");
	   string.append(validate.validateemptylendisplay());
	  return  string;
	  
	  
  }
}
